package com.lixw.saa.controller;

import com.alibaba.cloud.ai.dashscope.agent.DashScopeAgent;
import com.alibaba.cloud.ai.dashscope.agent.DashScopeAgentOptions;
import com.alibaba.cloud.ai.dashscope.api.DashScopeAgentApi;
import org.springframework.ai.chat.prompt.Prompt;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName: MenuCallAgentController
 * @Description:
 * @Author: xuweiLi
 * @Create: 2025/10/5 11:06
 **/
@RestController
public class MenuCallAgentController {
    //百炼平台的appid
    @Value("${spring.ai.dashscope.agent.options.app-id}")
    private String appId;
    //百炼云端智能体操作/调用对象
    private DashScopeAgent dashScopeAgent;
    //构造方法注入百炼智能体api对象 用于填充操作/调用对象
    public MenuCallAgentController(DashScopeAgentApi dashScopeAgentApi) {
        this.dashScopeAgent = new DashScopeAgent(dashScopeAgentApi);
    }

    @GetMapping("/eatAgent")
    public String eatAgent(@RequestParam(name = "topic", defaultValue = "今天吃什么") String topic) {
        DashScopeAgentOptions options = new DashScopeAgentOptions();
        options.setAppId(appId);
        Prompt prompt = new Prompt(topic, options);
        return dashScopeAgent.call(prompt).getResult().getOutput().getText();
    }


}